package com.jfinal.club._admin.wordsynonyms;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.club.my.wordsynonyms.MyWordsynonymsValidator;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.club.common.controller.BaseController;
import com.jfinal.kit.Ret;
import com.jfinal.club.common.model.Word;
import com.jfinal.club.common.model.Wordsynonyms;
import com.jfinal.club.index.IndexService;

/**
 * 近义词管理控制器
 */
public class WordsynonymsAdminController extends BaseController {

	@Inject
	WordsynonymsAdminService srv;

	public void index() {
		Page<Wordsynonyms> wordsynonymsPage = srv.paginate(getParaToInt("p", 1));
		setAttr("wordsynonymsPage", wordsynonymsPage);
		render("index.html");
	}

	/**
	 * 创建
	 */
	public void add() {
		render("add_edit.html");
	}

	/**
	 * 提交创建
	 */
	@Before(MyWordsynonymsValidator.class)
	public void save() {
		Wordsynonyms wordsynonyms = getBean(Wordsynonyms.class);
		//Word word = getBean(Word.class);
		//Ret ret = srv.save(wordsynonyms);
		Ret ret = srv.save(getLoginAccountId(), wordsynonyms);
		renderJson(ret);
	}

	/**
	 * 修改
	 */
	public void edit() {
		keepPara("p");	// 保持住分页的页号，便于在 ajax 提交后跳转到当前数据所在的页
		setAttr("wordsynonyms", srv.edit(getParaToInt("id")));
		render("add_edit.html");
	}

	/**
	 * 提交修改
	 */
	@Before(MyWordsynonymsValidator.class)
	public void update() {
		Wordsynonyms wordsynonyms = getBean(Wordsynonyms.class);
		Ret ret = srv.update(wordsynonyms);
		renderJson(ret);
	}
	/**
	 * 删除 wordsynonyms
	 */
	public void delete() {
		Ret ret = srv.delete(getParaToInt("id"));
		renderJson(ret);
	}
}


